/*
 * JanelaConfigurarPML.java
 *
 * Created on 24 de Outubro de 2008, 08:44
 */

package br.com.cpqd.ssar.mediador.gui;

import br.com.cpqd.ssar.mediador.ControladorPML;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author  carlos
 */
public class JanelaConfigurarPML extends javax.swing.JFrame {

    
    /*
     * Arquivo de Configuração da PML na Simulacao
     */
    String nomeArquivoPML;
    
    /*
     * Recebe o controlador de configuração da PML por referencia
     */
    ControladorPML controladorPML;
    
    /** Creates new form JanelaConfigurarPML */
    public JanelaConfigurarPML(String nomeArquivo, ControladorPML controlar) {
        
        this.nomeArquivoPML = nomeArquivo;
        this.controladorPML = controlar;             
        initComponents();
        setSelecionados();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jComboBoxZFinal = new javax.swing.JComboBox();
        jComboBoxYFinal = new javax.swing.JComboBox();
        jComboBoxXFinal = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jComboBoxZInicial = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxYInicial = new javax.swing.JComboBox();
        jComboBoxXInicial = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jButtonCancelar = new javax.swing.JButton();
        jButtonConfirmar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Configurar PML da Simulação");
        setBackground(new java.awt.Color(231, 240, 250));

        jPanel1.setBackground(new java.awt.Color(231, 240, 250));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Configurar PML"));

        jComboBoxZFinal.setModel(getCombo());

        jComboBoxYFinal.setModel(getCombo());

        jComboBoxXFinal.setModel(getCombo());
        jComboBoxXFinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxXFinalActionPerformed(evt);
            }
        });

        jLabel2.setText("X Final");

        jLabel4.setText("Y Final");

        jLabel6.setText("Z Final");

        jComboBoxZInicial.setModel(getCombo());
        jComboBoxZInicial.setPreferredSize(new java.awt.Dimension(15, 20));

        jLabel5.setText("Z Inicial");

        jComboBoxYInicial.setModel(getCombo());
        jComboBoxYInicial.setPreferredSize(new java.awt.Dimension(15, 20));

        jComboBoxXInicial.setModel(getCombo());
        jComboBoxXInicial.setPreferredSize(new java.awt.Dimension(15, 20));

        jLabel1.setText("X Inicial");

        jLabel3.setText("Y Inicial");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxXInicial, 0, 140, Short.MAX_VALUE)
                        .addGap(47, 47, 47)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jComboBoxXFinal, 0, 140, Short.MAX_VALUE)
                            .addComponent(jComboBoxZFinal, 0, 140, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jComboBoxZInicial, 0, 113, Short.MAX_VALUE)
                                .addGap(71, 71, 71)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                                .addGap(91, 91, 91))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jComboBoxYInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jComboBoxYFinal, 0, 142, Short.MAX_VALUE)
                                .addContainerGap())))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jComboBoxXInicial, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jComboBoxXFinal))
                .addGap(58, 58, 58)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jComboBoxYInicial, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBoxYFinal)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE))
                .addGap(72, 72, 72)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jComboBoxZInicial, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(jComboBoxZFinal))
                .addGap(94, 94, 94))
        );

        jPanel3.setBackground(new java.awt.Color(231, 240, 250));

        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/Cancelar.png"))); // NOI18N
        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jButtonConfirmar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/cpqd/ssar/gerenciador/gui/recursos/confirmar.png"))); // NOI18N
        jButtonConfirmar.setText("Confirmar");
        jButtonConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfirmarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(351, Short.MAX_VALUE)
                .addComponent(jButtonConfirmar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCancelar)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCancelar)
                    .addComponent(jButtonConfirmar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jComboBoxXFinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxXFinalActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jComboBoxXFinalActionPerformed

private void jButtonConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmarActionPerformed
    salvarConfiguracaoPML();
    dispose();
}//GEN-LAST:event_jButtonConfirmarActionPerformed

private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
    dispose();
}//GEN-LAST:event_jButtonCancelarActionPerformed

 /**
     * Retornar o valor modelo das Fontes dos usuário
     * @return modeloEditavel DefaultComboBoxModel
     */
    public DefaultComboBoxModel getCombo() {
        DefaultComboBoxModel lista = new DefaultComboBoxModel();
        int valor;
        valor=0;
        lista.addElement(valor);
        valor=8;
        lista.addElement(valor);
        valor=10;
        lista.addElement(valor);
        valor=12;
        lista.addElement(valor);      
        return lista;
    }
    
    public void salvarConfiguracaoPML(){
        Vector vetor = new Vector();
        vetor.add(0, jComboBoxXInicial.getSelectedItem());
        vetor.add(1, jComboBoxXFinal.getSelectedItem());
        vetor.add(2, jComboBoxYInicial.getSelectedItem());
        vetor.add(3, jComboBoxYFinal.getSelectedItem());
        vetor.add(4, jComboBoxZInicial.getSelectedItem());
        vetor.add(5, jComboBoxZFinal.getSelectedItem());   
        controladorPML.setCamadas(vetor);
        controladorPML.salvarConfiguracoesPML();
    }
    
    public void setSelecionados(){
        Vector vetor = new Vector();
        vetor = controladorPML.getCamadasPML();
        jComboBoxXInicial.setSelectedItem(vetor.get(0));
        jComboBoxXFinal.setSelectedItem(vetor.get(1));        
        jComboBoxYInicial.setSelectedItem(vetor.get(2));
        jComboBoxYFinal.setSelectedItem(vetor.get(3));
        jComboBoxZInicial.setSelectedItem(vetor.get(4));
        jComboBoxZFinal.setSelectedItem(vetor.get(5)); 
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonConfirmar;
    private javax.swing.JComboBox jComboBoxXFinal;
    private javax.swing.JComboBox jComboBoxXInicial;
    private javax.swing.JComboBox jComboBoxYFinal;
    private javax.swing.JComboBox jComboBoxYInicial;
    private javax.swing.JComboBox jComboBoxZFinal;
    private javax.swing.JComboBox jComboBoxZInicial;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration//GEN-END:variables

}
